﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using HandyControl.Controls;
using WWLauncher.Interface;
using WWLauncher.Model;
using WWLauncher.Util;
using WWLauncher.View.UserControls.Config;
using WWLauncher.ViewModel;
using Window = System.Windows.Window;

namespace WWLauncher.View.Other
{
    /// <summary>
    /// GradientBGDialog.xaml 的交互逻辑
    /// </summary>
    public partial class GradientBGDialog : IChildrenWindow
    {
        private readonly GradientBGParamListModel vm = new();
        public Dialog dialog;
        private readonly ThemeConfig config = MainViewModel.Instance().AppConfig.ThemeConfig;

        public GradientBGDialog()
        {
            this.DataContext = vm;
            InitializeComponent();
            this.Loaded += GradientBGDialog_Loaded;
            this.GradientBGsListBox.SelectionChanged += GradientBGsListBox_SelectionChanged;

        }

        private void GradientBGsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            GradientBGParam bgParam = e.AddedItems[0] as GradientBGParam;

            config.GradientBgParam = bgParam;
            config.TextColor = bgParam.TextColor;
            config.SelectedIndex = GradientBGsListBox.SelectedIndex;
        }

        private void GradientBGDialog_Loaded(object sender, RoutedEventArgs e)
        {
            GradientBGsListBox.SelectedIndex = config.SelectedIndex;
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            dialog.Close();
        }

        private void BGBorder_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

        }

        /// <summary>
        /// 移动窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Window.GetWindow(this).DragMove();
            }
        }


        public MainWindow ParentWindow { get; set; }
        public ConfigWindow ConfigWindow { get; set; }
    }
}
